package com.evenmo.string;

import org.junit.Test;

import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.net.URI;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;

/**
* @author: moyongjun
* @Date: 2019/10/25 11:54 下午
* @Description: 测试File类
*
*
*/
public class TestFile {

    @Test
    public void testFile(){
        File file =new File("/Users/moyongjun/testCreatFile");
        try {
           // boolean newFile = file.createNewFile();
        //    System.out.println("师傅创建文件"+newFile);
        } catch (Exception e) {
            e.printStackTrace();
        }

        boolean mkdirs = file.mkdirs();
        System.out.println("是否创建目录"+mkdirs);



    }

    /**
     * 测试File类
     */


    @Test
    public void testFiles(){
        Path path = Paths.get("/Users/moyongjun/testCreatFile");
        System.out.println(path);
        System.out.println(path.getFileName());

        URI uri = URI.create("file:///Users/moyongjun/learning.py");//如果不写file://会报错，报非法参数
        Path path1 = Paths.get(uri);
        System.out.println(path1);
        System.out.println(path1.getFileName());
    }

    @Test
    public void testBufferedReader(){
        try {
            BufferedReader bufferedReader = Files.newBufferedReader(Paths.get("/Users/moyongjun/learning.py"), StandardCharsets.UTF_8);
            String str=null;
            while ((str=bufferedReader.readLine())!=null){
                System.out.println(str);
            }
            bufferedReader.close();//finally块中处理
        } catch (IOException e) {
            e.printStackTrace();
        }




    }
}
